package com.firmboy.mybatis.hello;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;

/**
 * 测试
 *
 * @author firmboy
 * @create 2018-05-13 下午6:37
 **/
public class HelloWorld {


    public static void main(String[] args){
        String resource = "Configuration.xml";

        Reader reader;

        try{
            reader = Resources.getResourceAsReader(resource);
            SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
            SqlSession session = sqlMapper.openSession();

            try {
                User user = (User) session.selectOne("UserMapper.getUser", "0000069af3554ea587791a411e9bea63");
                System.out.println(user.getId() + "," + user.getName());
            } finally {
                session.close();
            }
        }catch(Exception e){
            e.printStackTrace();
        }

    }
}
